package com.byl.modules.core.controller;

import com.byl.common.modules.controller.BaseController;
import com.byl.modules.core.service.PartnerService;
import com.byl.sdk.bean.ResultBean;
import com.byl.sdk.utils.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class PartnerController extends BaseController {

    @Autowired
    PartnerService partnerService;

    @PostMapping("/wx/partner/register")
    public String register(@RequestBody Map map) {
        String pwd = MapUtils.getValue(map, "password");
        String confirm = MapUtils.getValue(map, "confirm");
        if (!pwd.equals(confirm)) {
            return fail("两次密码输入不一致!");

        }
        int rs = partnerService.register(map);
        if (rs == -1) {
            return fail("邀请码无效！");
        } else if (rs == 1) {
            return success("注册成功！");
        } else {
            return fail("注册失败！");

        }
    }
    @PostMapping("/api/partner/list")
    public String query(@RequestBody Map map){
        ResultBean bean= partnerService.query(map);
        return success("合伙人列表",bean);

    }
    @PostMapping("/api/partner/audit")
    public String audit(@RequestBody Map map){
        int rs=partnerService.audit(map);
        //获取状态
        String sta=MapUtils.getValue(map,"status");
        String msg="审核";
        if(sta.equals("3")){
            msg="拒绝";
        }

        return rs>0?success(msg+"成功"):fail(msg+"失败");
    }

    @GetMapping("/api/partner/statistics")
    public String statistics() {
        Map map = partnerService.statistics();
        return success("统计结果", map);
    }

    @PostMapping("/api/partner/updatetype")
    public String updatetype(@RequestBody Map map) {
        int rs = partnerService.updatetype(map);
        return rs > 0 ? success("操作成功!") : fail("操作失败!");
    }

}
